<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use think\Db;
use think\Exception;

class Qianzi4 extends Frontend
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function cha()
    {
        // 临时关闭当前模板的布局功能
        $this->view->engine->layout(false);
        return $this->fetch("cha");
    }
    public function cha_post()
    {
        $param = $_POST;
        $url = "http://xtp.hl-group.com.cn/";
        $urls = $url."index/index/cha_post_1";
        $res = sendCmd1($urls,'post',$param);
//        dump($res);die;
        return $res;
        //查询是否退统
//        $status_tui = db('list_three')->where('ids',$res['id'])->where(['batch_state'=>1])->field('id')->find();
//        if($status_tui){
//            return json(['code'=>-1,'msg'=>'查询失败1']);
//        }
//        return json(['code'=>1,'msg'=>'查询成功']);
    }
    public function cha_t()
    {
        $param = $_GET;
        if(empty($param)){
            $this->error('请先选择要查询的服务单的对象');
        }else{
            $url = "http://xtp.hl-group.com.cn/";
            $urls = $url."index/index/cha_post_1";
            $data = sendCmd1($urls,'post',$param);
            if($data['code'] <> 1){
                return $data['msg'];
            }
            $res = $data['data'];
            $res['car_use_nature_str'] = $this->car_use_nature_str($res['car_use_nature']);

            $tc_list = array();
            $k       = 0;
            $line    = 8;
            if ($res['main_standard']) {
                $tc_list[$k]['tczl']  = '机动车车损损失';
                $tc_list[$k]['bjmp']  = $res['main_franchise'];
                $tc_list[$k]['money'] = $res['main_money'];
                $tc_list[$k]['tcf']   = number_format($res['main_submit'], 2);

                $k = $k + 1;
            }
            if ($res['main_biao']) {
                $tc_list[$k]['tczl']  = '机动车第三者责任';
                $tc_list[$k]['bjmp']  = $res['main_ji'];
                $tc_list[$k]['money'] = $res['main_santong'];
                $tc_list[$k]['tcf']   = number_format($res['main_yingjiao'], 2);
                $k = $k + 1;
            }
            if ($res['dao_biao']) {
                $tc_list[$k]['tczl']  = '医保外用药';
                $tc_list[$k]['bjmp']  = $res['dao_ji'];
                $tc_list[$k]['money'] = $res['dao_tong'];
                $tc_list[$k]['tcf']   = number_format($res['dao_ying'], 2);
                $k                    = $k + 1;
            }
            if ($res['siji_biao']) {
                $tc_list[$k]['tczl']  = '机动车车上人员-司机 *1';
                $tc_list[$k]['bjmp']  = $res['siji_ji'];
                $tc_list[$k]['money'] = $res['siji_tong'];
                // $tc_list[$k]['tcf']= $res['siji_ying'];
                $tc_list[$k]['tcf'] = number_format($res['siji_ying'], 2);
                $k = $k + 1;
            }
            if ($res['ck_biao']) {
                $tc_list[$k]['tczl']  = '机动车车上人员-乘客 *' . (string)($res['car_carry_peo'] - 1);
                $tc_list[$k]['bjmp']  = $res['ck_ji'];
                $tc_list[$k]['money'] = $res['ck_tong'];
                $tc_list[$k]['tcf']   = number_format($res['ck_ying'], 2);
                $k                    = $k + 1;
            }

            if($res['dw_biao']){
                $tc_list[$k]['tczl']='外部电网故障损失险';
                $tc_list[$k]['bjmp'] = $res['dw_ji'];
                $tc_list[$k]['money']= $res['dw_tong'];
                $tc_list[$k]['tcf']= $res['dw_ying'];
                $k=$k+1;
            }
            $site = $data['site'];
            $site['bjd_ewm'] = $url.$site['bjd_ewm'];
            $site['bjd_logo'] = $url.$site['bjd_logo'];
            $site['bjd_bj'] = $url.$site['bjd_bj'];
            $site['bjd_fwz'] = $url.$site['bjd_fwz'];
            $this->assign('site', $site);
            $line = $line - $k;
            $this->assign('tc_list', $tc_list);
            $this->assign('line', $line);
            $tiaokuan = $res['tiaokuan'];
            $this->assign('tiaokuan', $tiaokuan);
            $this->assign('res', $res);
//            dump($res);die;
            if(!empty($res['sign']['sign_pic'])){
                $res['sign']['sign_pic'] = $url.$res['sign']['sign_pic'];
            }
            $sign = $res['sign'];
            $this->assign('sign', $sign);
            
            $this->assign('orderid',$res['id']);
            // 临时关闭当前模板的布局功能
            $this->view->engine->layout(false);

            return $this->fetch('cha_t');
        }
    }

    public function car_use_nature_str($value)
    {
        try {
            return model('Constants')->CAR_USE_NATURE[$value];
        } catch (Exception $e) {
            return '';
        }
    }
}